// import yamlurl from '../custom/yamljson.json';

class basemsg {
    constructor($state,ctgNotification, $scope, commonSrv) {
        "ngInject";
        this._commonSrv = commonSrv;
        this._state = $state;
        this._notification = ctgNotification;
        this.kDbCode = $scope.$parent.vm.kDbCode;
        $scope.$parent.vm.step = 0;
        this.fData = $scope.$parent.vm.fData;

        if ($scope.$parent.vm.lessee_id) {
            this.notEditCode=true;
            this._commonSrv('get', '/ctg-imageconsole-web/namespace/detail', {
                id: $scope.$parent.vm.lessee_id
            }).catch(()=>{
                this._notification.error('获取租户信息有误。')
            }).then((re) => {
                this.fData.baseInfo = {
                    name: re.namespaceName,
                    code: re.namespaceCode,
                    cpu: re.cpuQuota,
                    ram: re.memoryQuota,
                    living_count: re.podQuota,
                    applied_count: re.rcQuota
                };
                
            })
        } else {
            this.fData.baseInfo = {};
        }
    }
    checkHasCode() {
        this.loading_code = true;
        this.hasCode = false;
        this._commonSrv('get', '/ctg-imageconsole-web/namespace/checkIsExist', {
            clusterCode: this.kDbCode,
            namespaceCode: this.fData.baseInfo.code
        }).then((data) => {
            // console.log(data)
            if (data) {
                this.hasCode = true;
            } else {
                this.hasCode = false;
            }
        }).catch(()=>[
            this._notification.error('检查租户编码有误。')
        ]).finally(() => {
            this.loading_code = false;
        })
    }
    checkHide() {
        this.hasCode = false;
    }
    next() {
        var item = this.fData.baseInfo;
        var params = {
            namespaceCode: item.code,
            cpuQuota: item.cpu,
            memoryQuota: item.ram,
            podQuota: item.living_count,
            // rcQuota: item.applied_count
        };
        this.nextLoading = true;
        this._commonSrv('post', '/ctg-imageconsole-web/namespace/combineJson', params).then((data) => {

            this.fData.yJsonList = data;
            // Object.keys(data).forEach((item, index) => {
            //     this.fData.yJsonList.push(data[item]);
            // });
            // console.log(data);
            this._state.go('create.custom');
        }).finally(() => {
            this.nextLoading = false;
        });
        // this.fData.yJsonList=[];
        // var objs={yd:yamlurl[0],ie:yamlurl[0],ei:yamlurl[0]};
        // Object.keys(objs).forEach((item,index)=>{
        //     this.fData.yJsonList.push(objs[item]);
        // });

    }
}
export default basemsg;